#ifndef DEVICE_CONSOLE_H
#define DEVICE_CONSOLE_H

#include <QWidget>
#include <QThread>
#include <QStandardItemModel>
#include <QButtonGroup>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QUrl>
#include "message.h"
#include "tcp_thread.h"

namespace Ui {
class Device_Console;
}

class Device_Console : public QWidget
{
    Q_OBJECT

public:
    explicit Device_Console(QWidget *parent = nullptr);
    ~Device_Console();

    void DoInit(char *);//初始化

signals:
    void s_Logout();//退出登陆
    void s_closeSockfd();
    void s_sendMsgToDevice(QVariant emitmsg);
    void s_sendMsgToAlarm(QVariant emitmsg);
    void s_sendMsgToMedia(QVariant emitmsg);
    void s_connectDeviceSockfd(QString ip,qint16 port);
    void s_connectAlarmSockfd(QString ip,qint16 port);
    void s_connectMediaSockfd(QString ip,qint16 port);

private slots:
    void ChangeDevicePage(const QModelIndex &index);
    void RecvDeviceMsg(QVariant v_msg);//接收deviceServer数据包
    void RecvAlarmMsg(QVariant v_msg);//接收alarmServer数据包
    void RecvMediaMsg(QVariant v_msg);//接收mediaServer数据包
    void on_pushButton_getAirStatuse_clicked();
    void on_pushButton_getRefStatuse_clicked();
    void on_pushButton_switchSet_clicked();
    void on_pushButton_modeSet_clicked();
    void on_pushButton_windSet_clicked();
    void on_pushButton_tempSet_clicked();
    void on_pushButton_freezeTempSet_clicked();
    void on_pushButton_freshTempSet_clicked();
    void on_pushButton_airAlarmGet_clicked();
    void on_pushButton_airAlarmClear_clicked();
    void on_pushButton_refAlarmGet_clicked();
    void on_pushButton_refAlarmClear_clicked();
    void on_pushButton_videoClose_clicked();
    void on_pushButton_videoOpen_clicked();
    void on_logoutPushButton_clicked();
    void on_homePushButton_clicked();
    void on_addpushButton_clicked();

private:
    Ui::Device_Console *ui;

    int  g_iGetDeviceNum = 0;
    int  g_iNowDeviceNum = 0;
    int  g_iDeviceStateType = -1;
    char g_cNowDeviceMac[32] = {0};
    char g_cUserName[NAME_PASSWORD_LEN] = {0};
    char g_cAllDeviceMac[1024] = {0};
    bool g_bGetAllStateFlag = false;


    TCP_Thread *device_TCP =nullptr;
    TCP_Thread *alarm_TCP =nullptr;
    TCP_Thread *media_TCP =nullptr;
    QStandardItemModel *deviceListModel = nullptr;
    QStandardItemModel *airAlarmModel = nullptr;
    QStandardItemModel *refAlarmModel = nullptr;
    QButtonGroup *buttonGroupSwitch = nullptr;
    QButtonGroup *buttonGroupWind = nullptr;
    QButtonGroup *buttonGroupMode = nullptr;
    QMediaPlayer* refPlayer = nullptr;
    QVideoWidget* refVideoWidget = nullptr;

    void WrongBox(QString title,QString word);//错误窗口
    void SendMsgToDevice(int commandType, int curSeq, int custom1, int custom2,int total_len, char *data1,...);//发送消息toDeviceServer
    void SendMsgToAlarm(int commandType, int curSeq, int custom1, int custom2,int total_len, char *data1,...);//发送消息toAlarmServer
    void SendMsgToMedia(int commandType, int curSeq, int custom1, int custom2,int total_len, char *data1,...);//发送消息toAlarmServer
    void SendQueryMsg();//发送查询设备消息
    void TakeQueryMsg(MsgStruct recvMsg);//接收查询设备结果
    void TakeAddDeviceMsg(MsgStruct recvMsg);//接收添加设备结果
    void TakeGetStatusMsg(MsgStruct recvMsg);//接收获取状态结果
    void TakeSetStatusMsg(MsgStruct recvMsg);//接收设置状态结果
    void TakeAlarmMsg(MsgStruct recvMsg);//处理设备报警通知
    void TakeGetAlarmMsg(MsgStruct recvMsg);//处理获取报警通知
    void TakeGetURLMsg(MsgStruct recvMsg);//处理获取URLMSG
    void AnalyseDeviceList(char *allDeviceMac);//分析获得设备清单
    void AddDeviceList(QString);//添加设备至清单


protected:
    virtual void closeEvent(QCloseEvent *event);//关闭事件
};
#endif // DEVICE_CONSOLE_H
